#include <iostream>
#include <vector>
using namespace std;

class st {
	int power;
	vector<vector<int>> gh, jst;
	vector<vector<pair<int, int>>> query;
	vector<int> deep, father, vis, ans;

	int find(int x)
	{
		return father[x] == x ? x : father[x] = find(father[x]);
	}

	int log2(int n)
	{
		int ans = 0;
		while ((1 << ans) <= (n >> 1)) {
			ans++;
		}
		return ans;
	}

	void dfs(int u, int f)
	{
		deep[u] = deep[f] + 1;
		jst[u][0] = f;
		for (int i = 1; i <= power; i++) {
			jst[u][i] = jst[jst[u][i - 1]][i - 1];
		}

		for (auto v : gh[u]) {
			if (v != f) {
				dfs(v, u);
			}
		}
	}

	int lca(int a, int b)
	{
		if (deep[a] < deep[b]) {
			swap(a, b);
		}

		for (int p = power; p >= 0; p--) {
			if (deep[jst[a][p]] >= deep[b]) {
				a = jst[a][p];
			}
		}

		if (a == b) {
			return a;
		}

		for (int p = power; p >= 0; p--) {
			if (jst[a][p] != jst[b][p]) {
				a = jst[a][p];
				b = jst[b][p];
			}
		}

		return jst[a][0];
	}

	void tarjan(int u, int f)
	{
		vis[u] = 1;
		for(auto v : gh[u]){
			if(v != f){
				tarjan(v, u);
				father[v] = u;
			}
		}

		for(auto e : query[u]){
			int v = e.first;
			int idx = e.second;
			if(vis[v]){
				int lca = find(v);
				ans[idx] = deep[u] + deep[v] - 2*deep[lca];
			}
		}

	}

    public:
	st(int n) : power(log2(n)), deep(n + 1, 0), father(n + 1, 0), vis(n + 1, 0), gh(n + 1), query(n + 1), jst(n + 1, vector<int>(power + 1, 0))
	{
		for (int i = 0, u, v; i < n - 1; i++) {
			cin >> u >> v;
			gh[u].push_back(v);
			gh[v].push_back(u);
		}
		dfs(1, 0);
	}

	void run()
	{
		int n = 0;
		cin >> n;
		for (int i = 0, u, v; i < n; i++) {
			cin >> u >> v;
			int llca = lca(u, v);
			cout << deep[u] + deep[v] - 2 * deep[llca] << '\n';
		}
	}

	void run2()
	{
		int n = 0;
		cin >> n;
		ans.resize(n, 0);
		for(int i = 0; i < father.size(); i++){
			father[i] = i;
		}
		for (int i = 0, u, v; i < n; i++) {
			cin >> u >> v;
			query[u].push_back({v, i});
			query[v].push_back({u, i});
		}
		tarjan(1, 0);
		for(auto dist : ans){
			cout << dist << '\n';
		}
	}
};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n = 0;
	cin >> n;
	st tst(n);
	tst.run2();
	return 0;
}